package com.qdlc.p2p.biz.executer.impl;

import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.qdlc.p2p.biz.executer.BaseExecuter;
import com.qdlc.p2p.common.constant.Global;
import com.qdlc.p2p.common.constant.LogTplNid;
import com.qdlc.p2p.common.constant.NoticeTplNid;
import com.qdlc.p2p.common.util.BeanUtil;
import com.qdlc.p2p.dal.dao.AccountDao;
import com.qdlc.p2p.dal.dao.AccountLogDao;
import com.qdlc.p2p.dal.dao.ExperienceDao;
import com.qdlc.p2p.dal.dao.UserCacheDao;
import com.qdlc.p2p.dal.dto.Account;
import com.qdlc.p2p.dal.dto.AccountLog;

/**
 * 体验金投标
 *
 * @author cx
 * @version 2.0
 * @since 2014-5-22
 */
@Service
@Scope(value=ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class BorrowExperienceTenderExcuter extends BaseExecuter {

    protected AccountLogDao accountLogDao;
    protected ExperienceDao experienceDao;
    protected UserCacheDao userCacheDao;
    protected AccountDao accountDao;

    @Override
    public void prepare() {
        accountLogDao = (AccountLogDao) BeanUtil.getBean("accountLogDao");
        userCacheDao = (UserCacheDao) BeanUtil.getBean("userCacheDao");
        experienceDao = (ExperienceDao) BeanUtil.getBean("experienceDao");
        accountDao = (AccountDao) BeanUtil.getBean("accountDao");
    }

    @Override
    public void addAccountLog() {
        Global.setTransfer("web_url", WEB_URL);
        Account account = accountDao.findByUserId(this.user.getUserId());
        AccountLog log = new AccountLog(super.user, LogTplNid.EXPERIENCE_TENDER, super.toUser);
        log.setMoney(this.money);
        log.setTotal(account.getTotal());
        log.setUseMoney(account.getUseMoney());
        log.setNoUseMoney(account.getNoUseMoney());
        log.setCollection(account.getCollection());
        log.setRemark(this.getLogRemark());

        accountLogDao.save(log);
    }

    @Override
    public void handleNotice() {
        sendNotice(user, NoticeTplNid.TENDER);
    }
}
